﻿
#region Usings

using FasterWPF;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Shapes;
using Thriple.Controls;

#endregion

namespace FasterWPFExtras
{
    public class ContentControl3DArgs
    {
        private ContentControlEnum _innerEnum;

        public ContentControlEnum InnerEnum
        {
            get
            {
               return _innerEnum; 
            }
        }

        public ContentControl3DArgs(ContentControlEnum innerEnum)
        {
            _innerEnum = innerEnum;
        }
    }

    public class ContentControl3DParent : FasterWPF.IParent 
    {         
        //this is ANA?
        public object Generate<T>(object chain, T args, Action<ContentControl> addUIElementsAction)
        {
            return chain;
        }

        #region IParent

        //this is BIND
        public object Add<T>(object chain, string key, T args, Border itemToAdd)
        {
            if (args is ContentControl3DArgs)
            {
                if ((args as ContentControl3DArgs).InnerEnum == ContentControlEnum.Front)
                {
                    ((ContentControl3D)chain).Content = itemToAdd;
                }
                else 
                {
                    ((ContentControl3D)chain).BackContent = itemToAdd;
                }
            }
            
            return chain;
        }

        public void Remove(object chain, string key, Border itemToRemove)
        {
            if (((ContentControl3D)chain).Content == itemToRemove)
            {
                ((ContentControl3D)chain).Content = null;
            }
            if (((ContentControl3D)chain).BackContent == itemToRemove)
            {
                ((ContentControl3D)chain).BackContent = null;
            }

            IComposite ic = (IComposite)(((ContentControl3D)chain).GetIComposite<ContentControl3D>());
            ic.RemoveFromChain(itemToRemove);
        }

        public Dictionary<string, object> RetrieveDictionary(object chain)
        {
            return ((ContentControl3D)chain).GetCompositeLookupDictionary<ContentControl3D>();
        }
        
        //this is CATA?
        public List<Border> RetrieveCollection(object chain)
        {
            List<Border> lb = new List<Border>();
            foreach (var kvp in ((ContentControl3D)chain).GetCompositeLookupDictionary<ContentControl3D>())
            {
                lb.Add((Border)kvp.Value);
            }

            return lb;
        }

        #endregion

        public void ClearCollection(object chain)
        {
        }

        public void BeforeSortCollection<T>(object chain, object args, int row, int column, FasterWPF.CommonExt.SortOrder sortOrder)
                  where T : FrameworkElement
        { }

        public void BeforeSortCollection1Then2<T>(object chain, object args, int row, int column, int row2, int column2, FasterWPF.CommonExt.SortOrder sortOrder, FasterWPF.CommonExt.SortOrder sortOrder2)
  where T : FrameworkElement
        { }
        
        public void AfterSortCollection<T>(object chain)
             where T : FrameworkElement
        { }

        public void InnerSortCollection(object chain, int row, int column, string key, ref int counter, ContentControl3D itemToReAdd)
        {
            throw new NotImplementedException();
        }
        
        public void SetSelected(object chain, ContentControl3D itemToSetAsSelected)
        {
        }

        //public void GetSelected
        //    return (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem);

    }
}
